package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Teacher;

public class TeacherDao {
   private static Teacher[] teac = new Teacher[5];
    public boolean addTeacher(Teacher tea) {

     int index = -1;
        for (int i = 0; i < teac.length; i++) {
            if (teac[i]==null){
                index = i;
                break;
            }
        }
        if (index==-1){
            return false;
        }else {
            teac[index] = tea;
            return true;
        }
    }

    public Teacher[] findAllTeacher() {
        return teac;
    }

    public void deleteTeacher(String id) {
        int index = getIndex(id);
        if (index!=-1){
            teac[index]=null;
        }
    }


    public void updateTeacher(String id, Teacher ter) {
        int index = getIndex(id);
        if (index!=-1){
            teac[index] = ter;
        }
    }

    public int getIndex(String id){
        int index = -1;
        for (int i = 0; i < teac.length; i++) {
            Teacher tea = teac[i];
            if (tea!=null && tea.getId().equals(id)){
                index = i;
                break;
            }
        }
        return index;
    }
}
